package com.zhiyou100.www.bbs.function.topic;

import com.zhiyou100.www.bbs.dao.TableTitleDao;
import com.zhiyou100.www.bbs.entityclass.TableUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @packageName: ${NAME}
 * @className: ${PACKAGE_NAME}
 * @Description: TODO 添加话题
 * @author: yang
 * @date: 6/12/20
 */
@WebServlet(name = "AddTheTopic", urlPatterns = "/AddTheTopic")
public class AddTheTopic extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        // 设定编码集
        response.setContentType("text/html;charset=UTF-8");
        // 设定类型

        String tableHead = request.getParameter("tableHead");
        String tbCommentBody = request.getParameter("tbCommentBody");
        // 获取参数

        TableUser user = (TableUser) request.getSession().getAttribute("user");
        // 获取 session 中的 user 数据

        TableTitleDao tableTitleDao = new TableTitleDao();
        // 创建 话题dao 类
        tableTitleDao.addTopic(user, tableHead, tbCommentBody);
        // 添加话题

        response.sendRedirect("/bbs/jsp/homepage.jsp");
        // 转发到主页


    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
